package com.qf.Dao.Impl;


import com.qf.Dao.UserDao;
import com.qf.Entity.User;
import com.qf.Util.DruidUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/*2021/10/9*/public class UserDaoImpl implements UserDao {
    QueryRunner queryRunner=new QueryRunner();
    @Override
    public User selectUser(String uAccount) {
        User user=null;
        try {
             user=queryRunner.query(DruidUtil.getConnection(), "select u_id uId, u_account uAccount, u_password uPassword from user where u_account=?;", new BeanHandler<>(User.class), uAccount);
            return user;
        } catch (SQLException e) {
            throw new RuntimeException("登录查询用户信息时出现异常："+e.getMessage());
        }
    }

    @Override
    public Integer updatePassword(String uAccount, String uPassword) {

        try {
            return queryRunner.update(DruidUtil.getConnection(), "update user set u_password=? where u_account=?",uPassword,uAccount);
        } catch (SQLException e) {
            throw new RuntimeException("修改用户密码信息时出现异常："+e.getMessage());
        }
    }
}
